﻿using System;
using Castle.ActiveRecord;
using NHibernate.Expression;
using NHibernate;
using Hadlow.Jobvertizer.Models;
using Hadlow.Jobvertizer.Repositories;

namespace Hadlow.Jobvertizer.Repositories
{
    public class JobRepository : Repository<Job>, IJobRepository
    {
        public Job GetFeaturedJob()
        {
            ICriterion featuredIsTrue = Expression.Eq("Featured", true);
            Order[] orders = new Order[] { Order.Desc("Id") };
            return FindFirst(orders, featuredIsTrue);
        }

        public Job[] Search(IJobSearchCriteria criteria)
        {
            return FindAll(criteria.GetCritera());
        }
    }
}
